package com.wlb.address.split.rule;

import com.wlb.address.split.domain.AddrLevel;
import com.wlb.address.split.domain.GeoTerm;
import com.wlb.address.split.process.FusionResultSet;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 经验规则的集合
 * User: xiaotong.dxt
 * Date: 13-8-8
 * Time: 下午2:24
 * To change this template use File | Settings | File Templates.
 */
public class ExperienceRuleSet {
    private static  ExperienceRuleSet experienceRuleSet;


    public synchronized  static ExperienceRuleSet getInstance() {
        if (experienceRuleSet == null) {
            experienceRuleSet = new ExperienceRuleSet();
            experienceRuleSet.init();

        }

        return experienceRuleSet;
    }

    private ExperienceRuleSet() {

    }

    public void init() {

        cityWithChengquDistrict.add("汕尾市");
        cityWithChengquDistrict.add("汕尾");
        cityWithChengquDistrict.add("大同市");
        cityWithChengquDistrict.add("大同");
        cityWithChengquDistrict.add("阳泉市");
        cityWithChengquDistrict.add("阳泉");
        cityWithChengquDistrict.add("长治市");
        cityWithChengquDistrict.add("长治");
        cityWithChengquDistrict.add("晋城市");
        cityWithChengquDistrict.add("晋城");

        cityWithKuangquDistrict.add("大同市");
        cityWithKuangquDistrict.add("大同");
        cityWithKuangquDistrict.add("阳泉市");
        cityWithKuangquDistrict.add("阳泉");


        cityWithJiaoquDistrict.add("长治市");
        cityWithJiaoquDistrict.add("长治");
        cityWithJiaoquDistrict.add("阳泉市");
        cityWithJiaoquDistrict.add("阳泉");

        cityWithDongquXiquDistrict.add("攀枝花市");
        cityWithDongquXiquDistrict.add("攀枝花");


        townSuffixSet.add("街道");
        townSuffixSet.add("街道办");
        townSuffixSet.add("虚拟街道办事处");
        townSuffixSet.add("街道办事处");
        townSuffixSet.add("办事处");


        communitySuffixSet.add("社区");
        communitySuffixSet.add("居委会");
        communitySuffixSet.add("虚拟社区");
        communitySuffixSet.add("虚拟居委会");
        communitySuffixSet.add("虚拟社区居委会");
        communitySuffixSet.add("虚拟社区居民委员会");
        communitySuffixSet.add("社区居民委员会");
        communitySuffixSet.add("社区居委会");
        communitySuffixSet.add("村委会");
        communitySuffixSet.add("村民委员会");
        communitySuffixSet.add("牧委会");


        /////添加道路相关的处理////
        roadSuffixSet.add("大街");
        roadSuffixSet.add("大道");
        roadSuffixSet.add("国道");
        roadSuffixSet.add("省道");
        roadSuffixSet.add("县道");
        roadSuffixSet.add("乡道");
        roadSuffixSet.add("东街");
        roadSuffixSet.add("南街");
        roadSuffixSet.add("西街");
        roadSuffixSet.add("北街");
        roadSuffixSet.add("中街");
        roadSuffixSet.add("一街");
        roadSuffixSet.add("二街");
        roadSuffixSet.add("三街");
        roadSuffixSet.add("四街");
        roadSuffixSet.add("五街");
        roadSuffixSet.add("六街");
        roadSuffixSet.add("七街");
        roadSuffixSet.add("八街");
        roadSuffixSet.add("九街");
        roadSuffixSet.add("十街");

        roadSuffixSet.add("一道");
        roadSuffixSet.add("二道");
        roadSuffixSet.add("三道");
        roadSuffixSet.add("四道");
        roadSuffixSet.add("五道");
        roadSuffixSet.add("六道");
        roadSuffixSet.add("七道");
        roadSuffixSet.add("八道");
        roadSuffixSet.add("九道");
        roadSuffixSet.add("十道");

        //////天津市红桥区勤俭道十一段天津市求真小学///
        roadSuffixSet.add("一段");
        roadSuffixSet.add("二段");
        roadSuffixSet.add("三段");
        roadSuffixSet.add("四段");
        roadSuffixSet.add("五段");
        roadSuffixSet.add("六段");
        roadSuffixSet.add("七段");
        roadSuffixSet.add("八段");
        roadSuffixSet.add("九段");
        roadSuffixSet.add("十段");

        roadSuffixSet.add("东段");
        roadSuffixSet.add("南段");
        roadSuffixSet.add("西段");
        roadSuffixSet.add("北段");
        roadSuffixSet.add("中段");


        roadSuffixSet.add("一路");
        roadSuffixSet.add("二路");
        roadSuffixSet.add("三路");
        roadSuffixSet.add("四路");
        roadSuffixSet.add("五路");
        roadSuffixSet.add("六路");
        roadSuffixSet.add("七路");
        roadSuffixSet.add("八路");
        roadSuffixSet.add("九路");
        roadSuffixSet.add("十路");

        roadSuffixSet.add("横街");
        roadSuffixSet.add("厚街");
        roadSuffixSet.add("庙街");
        roadSuffixSet.add("前街");
        roadSuffixSet.add("后街");
        roadSuffixSet.add("条街");
        roadSuffixSet.add("下街");
        roadSuffixSet.add("新街");
        roadSuffixSet.add("正街");
        roadSuffixSet.add("直街");
        roadSuffixSet.add("道街");
        roadSuffixSet.add("食街");
        roadSuffixSet.add("南路");
        roadSuffixSet.add("西路");
        roadSuffixSet.add("中路");
        roadSuffixSet.add("东路");
        roadSuffixSet.add("北路");
        roadSuffixSet.add("东巷");
        roadSuffixSet.add("南巷");
        roadSuffixSet.add("西巷");
        roadSuffixSet.add("北巷");
        roadSuffixSet.add("中巷");


        /////交叉口描述信息////
        crossAddrInfoSet.add("交口");
        crossAddrInfoSet.add("交叉");
        crossAddrInfoSet.add("交叉口");
        crossAddrInfoSet.add("交接处");
        crossAddrInfoSet.add("交界");
        crossAddrInfoSet.add("交界处");
        crossAddrInfoSet.add("的交界处");
        crossAddrInfoSet.add("交汇");
        crossAddrInfoSet.add("交汇处");

        //中文数字的情况
        charNumSet.add("〇");//0
        charNumSet.add("一");
        charNumSet.add("二");
        charNumSet.add("三");
        charNumSet.add("四");
        charNumSet.add("五");
        charNumSet.add("六");
        charNumSet.add("七");
        charNumSet.add("八");
        charNumSet.add("九");
        charNumSet.add("十");
        ////零、壹、贰、叁、肆、伍、陆、柒、捌、玖////
        charNumSet.add("零");//0
        charNumSet.add("壹");
        charNumSet.add("贰");
        charNumSet.add("叁");
        charNumSet.add("肆");
        charNumSet.add("伍");
        charNumSet.add("陆");
        charNumSet.add("柒");
        charNumSet.add("捌");
        charNumSet.add("玖");
    }

    /**
     * 道路后缀的集合
     */
    public Set<String> roadSuffixSet = new HashSet<String>();

    /**
     * 下辖"城区"区的城市
     */
    public Set<String> cityWithChengquDistrict = new HashSet<String>();

    /**
     * 下辖"矿区"区的城市
     */
    public Set<String> cityWithKuangquDistrict = new HashSet<String>();
    /**
     * 下辖"郊区"区的城市
     */
    public Set<String> cityWithJiaoquDistrict = new HashSet<String>();


    /**
     * 下辖"东区\西区"区的城市
     */
    public Set<String> cityWithDongquXiquDistrict = new HashSet<String>();


    /**
     * 四级区域的后缀
     */
    public Set<String> townSuffixSet = new HashSet<String>();

    /**
     * 社区的后缀
     */
    public Set<String> communitySuffixSet = new HashSet<String>();

    /**
     *  交叉口的判断
     */
    public Set<String> crossAddrInfoSet = new HashSet<String>();


    public static boolean IsRoadSuffix(String strWordName) {
        if (strWordName.equals("国道") || strWordName.equals("省道") ||
                strWordName.equals("县道") || strWordName.equals("乡道") || strWordName.equals("胡同") || strWordName.equals("大街") || strWordName.equals("大道")) {
            return true;
        } else if (strWordName.endsWith("路") || strWordName.endsWith("道") || strWordName.endsWith("街") || strWordName.endsWith("弄") || strWordName.endsWith("巷") || strWordName.endsWith("条")) {
            return true;
        }
        return false;
    }

    public static boolean IsRoad(String strWordName) {
        int nSize = strWordName.length();
        if (nSize == 1 || strWordName.equals("街道")) {
            return false;
        }
        boolean bFaild = false;
        if ((strWordName.endsWith("路") &&
                !strWordName.endsWith("公路")) ||
                strWordName.endsWith("国道") ||
                strWordName.endsWith("省道") ||
                strWordName.endsWith("县道") ||
                strWordName.endsWith("乡道") ||
                (strWordName.endsWith("道") &&
                        !strWordName.endsWith("管道") &&
                        !strWordName.endsWith("频道") &&
                        !strWordName.endsWith("隧道") &&
                        !strWordName.endsWith("街道")) ||
                (strWordName.endsWith("街") &&
                        !strWordName.endsWith("商业街") &&
                        !strWordName.endsWith("步行街")) ||
                strWordName.endsWith("巷") ||
                strWordName.endsWith("弄") ||
                strWordName.endsWith("胡同") ||
                strWordName.endsWith("条")) {
            return true;
        }
        return false;
    }

    public static boolean IsCommunity(String strTemp1) {
        if (strTemp1.endsWith("里") || strTemp1.endsWith("社区") || strTemp1.endsWith("村"))
            return true;
        return false;
    }

    //对一个字符串进行判定 其属于18级中的哪一级
    public static boolean AdminArea_Community_Street_Decide(List<GeoTerm> termOut, int git, String strWordName, FusionResultSet fussionResultSet) {

        //如果是单字 则不用判断
        if (strWordName.length() == 1) {
            return false;
        }
        //道路 poi都不存在的时候
        if (!fussionResultSet.hasLevel(AddrLevel.AL_ROAD) && !fussionResultSet.hasLevel(AddrLevel.AL_SUB_ROAD) && !fussionResultSet.hasLevel(AddrLevel.AL_POI)) {
            boolean bSuffix = false;

        }
        return false;
    }

    public static AddrLevel GetAdminAreaLevel(String strtemp, AtomicBoolean bSuffix) {

        int nWordSize = strtemp.length();
        if (strtemp.endsWith("省")) {
            if (strtemp.length() == 1)
                bSuffix.set(true);
            return AddrLevel.AL_PROVINCE;

        } else if ((strtemp.endsWith("市") && !strtemp.endsWith("超市") && !strtemp.endsWith("门市")) || strtemp.endsWith("特别行政区") || strtemp.endsWith("盟") || strtemp.endsWith("自治州")) {
            return AddrLevel.AL_CITY;
        } else if (strtemp.endsWith("组") || strtemp.endsWith("队") || strtemp.endsWith("社")) {

            if (nWordSize == 1)
                bSuffix.set(true);
            if (strtemp.length() > 1) {
                char chDigital = strtemp.charAt(strtemp.length() - 2);
                //如果结尾前是数字，则表示是N队 N组的情况 是GROUP的正确表示形式
                if ((chDigital >= 48 && chDigital <= 57) || (charNumSet.contains(chDigital))) {
                    return AddrLevel.AL_GROUP;
                }
                return AddrLevel.AL_NotFound;

            }
            return AddrLevel.AL_UNKNOWN;
        } else if ((!strtemp.endsWith("新村") && strtemp.endsWith("村")) || strtemp.endsWith("社区") || strtemp.endsWith("虚拟社区") || strtemp.endsWith("社区居民委员会") || strtemp.endsWith("社区居委会") || strtemp.endsWith("居委会") || strtemp.endsWith("虚拟居委会") || strtemp.endsWith("虚拟社区居委会") || strtemp.endsWith("居民委员会") || strtemp.endsWith("虚拟社区居民委员会") || strtemp.endsWith("村委会") || strtemp.endsWith("村民委员会") || strtemp.endsWith("牧委会")) {
            return AddrLevel.AL_VILLAGE;
        } else if (strtemp.endsWith("技术开发区") || strtemp.endsWith("高新产业区") || strtemp.endsWith("高科技工业区") || strtemp.endsWith("经济开发区") || strtemp.endsWith("高新技术产业园") || strtemp.endsWith("开发区") ||
                strtemp.endsWith("高科园") ||//高科园
                strtemp.endsWith("物流园") ||//
                strtemp.endsWith("产业园") ||
                strtemp.endsWith("科技园") ||
                strtemp.endsWith("投资区") ||//投资区
                strtemp.endsWith("软件园") ||
                strtemp.endsWith("工业集中区") ||
                strtemp.endsWith("工业园区") ||
                strtemp.endsWith("工业园") ||
                strtemp.endsWith("工业区") ||
                strtemp.endsWith("创业园") ||
                strtemp.endsWith("工业新区") ||
                (strtemp.endsWith("园区") &&
                        !strtemp.endsWith("生活园区") &&
                        !strtemp.endsWith("东园区") &&
                        !strtemp.endsWith("南园区") &&
                        !strtemp.endsWith("西园区") &&
                        !strtemp.endsWith("北园区")
                )) {
            return AddrLevel.AL_DEV_ZONE;
        } else if ((strtemp.endsWith("区") &&
                !strtemp.endsWith("小区") &&
                !strtemp.endsWith("校区")) ||
                strtemp.endsWith("县") ||
                strtemp.endsWith("旗")) {
            if (nWordSize == 1)
                bSuffix.set(true);
            return AddrLevel.AL_DISTRICT;


        } else if (strtemp.endsWith("乡") ||
                strtemp.endsWith("镇") ||
                strtemp.endsWith("街道") ||
                strtemp.endsWith("街道办") ||
                strtemp.endsWith("街道办事处")) {
            return AddrLevel.AL_TOWN;

        }
        return AddrLevel.AL_NotFound;
    }

    public static Set<String> charNumSet = new HashSet<String>();
}



